package com.zhentao.login.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhentao.login.mapper.TRoleMapper;
import com.zhentao.login.mapper.TUserMapper;
import com.zhentao.login.mapper.TUserRoleMapper;
import com.zhentao.login.service.TUserRoleService;
import com.zhentao.nlz.project.dto.UserRoleDto;
import com.zhentao.nlz.project.login.TRole;
import com.zhentao.nlz.project.login.TUser;
import com.zhentao.nlz.project.login.TUserRole;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
* @author 不.凌
* @description 针对表【t_user_role(用户角色关联表)】的数据库操作Service实现
* @createDate 2024-09-22 20:51:43
*/
@Service
public class TUserRoleServiceImpl extends ServiceImpl<TUserRoleMapper, TUserRole>
    implements TUserRoleService{
@Autowired
private TUserRoleMapper userRoleMapper;
    @Autowired
    private TUserMapper userMapper;
    @Autowired
    private TRoleMapper roleMapper;
    @Override
    public boolean saveuserrole(UserRoleDto userRoleDto) {
        //添加用户表
        TUser user = new TUser();
        user.setUsername(userRoleDto.getUsername());
        user.setPassword(userRoleDto.getPassword());
        user.setPhone(userRoleDto.getPhone());
        user.setCreateTime(userRoleDto.getCreateTime());
        user.setDeptId(userRoleDto.getDeptId());

        int insertuser = userMapper.insert(user);
        System.out.println(user+"22222222222222222222222");
        //添加角色表
//        TRole role = new TRole();
//        role.setRoleName(userRoleDto.getRoleName());
//        System.out.println(role+"111111111111111111111");
//        int insertrole = roleMapper.insert(role);
        //获取俩表的id并添加进中间表
        TUserRole userRole = new TUserRole();
        Integer user1id=userMapper.seleUserId(userRoleDto.getUsername());
//        Integer role1id=roleMapper.seleRoleId(userRoleDto.getRoleName());
        userRole.setUserId(user1id);
        userRole.setRoleId(userRoleDto.getRoleId());
        int insertuserrole = userRoleMapper.insert(userRole);


        return true;
    }
}




